package p.jce.cert;

import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Provider;
import java.security.cert.CertPathValidator;
import java.security.cert.CertPathValidatorSpi;

import p.jce.BC;

public class RCertPathValidator {
	private static final class X extends CertPathValidator {

		protected X(CertPathValidatorSpi validatorSpi, Provider provider, String algorithm) {
			super(validatorSpi, provider, algorithm);
		}
	}

	public static CertPathValidator getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException {
		return CertPathValidator.getInstance(algorithm, provider);
	}

	public static CertPathValidator getInstance(String algorithm, String provider) throws NoSuchAlgorithmException,
			NoSuchProviderException {
		if ("BC".equals(provider)) {
			try {
				return new X((CertPathValidatorSpi) BC.newInstance("CertPathValidator", algorithm), null, algorithm);
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return CertPathValidator.getInstance(algorithm, provider);
	}

	public static CertPathValidator getInstance(String algorithm) throws NoSuchAlgorithmException {
		return CertPathValidator.getInstance(algorithm);
	}
}
